home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / srvymm30.lha / Surveymem3.0 / Docs / Programmers / SM_Marktest.s next >
Text File  |  1995-08-05  |  3KB  |  175 lines

  1.  
  2.     incdir "includes:"
  3.  
  4.     IFND    EXEC_EXECBASE_I
  5.     INCLUDE exec/execbase.I
  6.     ENDC
  7.  
  8.     IFND    EXEC_TYPES_I
  9.     INCLUDE exec/types.i
  10.     ENDC
  11.  
  12.     IFND    EXEC_LIBRARIES_I
  13.     INCLUDE exec/libraries.i
  14.     ENDC
  15.  
  16.     IFND EXEC_NODES_I        
  17.     include "exec/nodes.i"        
  18.     ENDC
  19.  
  20.     IFND EXEC_MEMORY_I
  21.     include "exec/memory.i"
  22.     ENDC
  23.     
  24.     IFND EXEC_EXEC_LIB_I
  25.     include "exec/exec_lib.i"
  26.     ENDC
  27.  
  28.     IFND    MISC_SURVEYMEM_I
  29.     include    "Misc/surveymem.i"
  30.     ENDC
  31.  
  32. CALLBASE:    MACRO
  33.         jsr    _LVO\1(a6)
  34.         ENDM
  35.  
  36.  
  37. ;3 handy macros to do all the desired operations.
  38. ;Feel free to change the names ;-)
  39.  
  40. SMON:        MACRO            ;ON=>counters begin to calc deltas.
  41.         moveq    #SMMF_On,d0
  42.         bsr    Sendmsg
  43.         ENDM
  44.  
  45. SMFRZ:        MACRO            ;FREEZE=>STOPS THE COUNTERS.
  46.         moveq    #SMMF_freeze,d0    ;then check the difference! yep!
  47.         bsr    Sendmsg
  48.         ENDM
  49.  
  50. SMOFF:        MACRO            ;OFF=>clears counters
  51.         moveq    #SMMF_Off,d0    ;not very useful here,though...
  52.         bsr    Sendmsg
  53.         ENDM
  54.  
  55.  
  56.  
  57. ;Sorry for all C users ! ...this time YOU will be obliged to look at
  58. ;an 'unfriendly language'
  59. ;Two reasons for this: * I only "Read C" enough to put things back to ASM!
  60. ;               * Let's reverse the roles once ;-)
  61. ;             (personal revenge from the RKRMs)
  62.  
  63. ;This source works Ok with Asmone,should be no problem with Devpac.
  64. ;case insensitive of course!
  65.  
  66.  
  67. ;    how you should do it:simple,no?
  68. ;
  69. ;
  70. ;    bsr    InitSMport
  71. ;    .....
  72. ;    SMON
  73. ;    < routine that allocates & deallocates memory >
  74. ;    SMOFF
  75. ;    .....
  76. ;    bsr    CloseSMport
  77.  
  78.  
  79.  
  80. ;***************************   Sample program   ******************************
  81.             section "dummy",code
  82.  
  83. BEGIN:    bsr    InitSMport        ;once for all
  84.  
  85.  
  86. ;example:program loses 212 bytes (Hmmm I just wonder why ;-)
  87. ;in fact,SM will show '216' but it's only bcoz of Exec's roundup routines
  88.  
  89.     SMON                ;counters....go!
  90.  
  91.     move.l    #212,d0
  92.     move.l    #MEMF_ANY+MEMF_CLEAR,d1
  93.     CALLEXEC ALLOCMEM
  94.  
  95.                     ;hmmmm...forgotten something?
  96.     SMFRZ
  97.  
  98.     bsr    CloseSMport
  99.     moveq    #0,d0
  100.     rts
  101.  
  102. ;****************************************************************************
  103.  
  104.  
  105.  
  106.  
  107.  
  108. ;----------------------------------------------------------------------------
  109. ;                The subroutines
  110. ;They test everything,so you don't have to worry if Surveymem is present/not.
  111. ;
  112. ;----------------------------------------------------------------------------
  113.  
  114.  
  115. ;Tries to create a replyport (so when we send a message,we can wait for it
  116. ;to be received)
  117. ;*****************
  118. InitSMport:
  119.     CALLEXEC Createmsgport
  120.     tst.l    d0
  121.     move.l    d0,SMreplyPort
  122.     rts
  123.  
  124.  
  125. CloseSMport:
  126.     tst.l    SMreplyport
  127.     bne.s    .close
  128.     rts
  129. .close:    move.l    SMreplyport,a0
  130.     CALLEXEC Deletemsgport
  131.     rts
  132.  
  133. ;
  134. ;The sendroutine.        INPUT:D0.l=SMMF_flag
  135. ;--------------------------------------------------------------------------
  136. SendMsg:tst.l    SMreplyport
  137.     bne.s    .ok
  138.     rts
  139. .ok:    movem.l a0-a6/d1-d7,-(sp)
  140.     bsr    .do
  141.     movem.l    (sp)+,a0-a6/d1-d7
  142.     rts
  143. .do:    lea    Themsg,a5
  144.     move.w    #SMm_SIZEOF,MN_LENGTH(a5)
  145.     move.l    SMReplyport,MN_REPLYPORT(a5)
  146.     move.l    #SM_Mark,SMm_code(a5)
  147.     move.l    d0,SMm_data(a5)
  148.     clr.b    FLG_port
  149.     CALLEXEC FORBID
  150.     lea    mainportname,a1
  151.     CALLBASE FINDPORT
  152.     tst.l    d0
  153.     beq.b    .noport
  154.     move.b    #1,FLG_port
  155.     move.l    d0,a0        ;if port=ok,send!
  156.     move.l    a5,a1
  157.     CALLBASE PUTMSG
  158. .noport:
  159.     CALLBASE PERMIT
  160.  
  161.     tst.b    FLG_port
  162.     bne    .mainportok
  163.     rts
  164. .mainportok:    
  165.     move.l    SMReplyport,a0
  166.     CALLBASE WAITPORT    ;then wait at our replyport (til SM has read our msg)
  167.     rts            ;of course we get back 'Themsg' in d0.
  168.  
  169. SMreplyport:    dc.l    0
  170. Themsg:    ds.b    SMm_SIZEOF
  171. FLG_port:    dc.b    0        ;internal flag:if non zero,means port was found
  172. mainportname:    dc.b    "Surveymem Main Port",0
  173.     even
  174.  
  175.